﻿using System;
using System.Linq;

namespace MyFitness.Model
{
    partial class Trainee : User
    {
        # region Declared Variables
        # endregion

        /// <summary>
        /// Copy Constructor
        /// </summary>
        /// <param name="t"></param>
        public Trainee(Trainee t) : base(t)
        {
            Gender = t.Gender;
            Height = t.Height;
            BirthDate = t.BirthDate;
        }

        /// <summary>
        /// Gets a Trainee Record from the date specified.
        /// </summary>
        /// <param name="d">The date of the record to pull.</param>
        /// <param name="CreateIfNoRecord">Defaults to creating a new record if one does not exist.</param>
        /// <returns>Only returns the first record found.  There should only be one record per day.</returns>
        public TraineeRecord GetTraineeRecord(DateTime d, bool CreateIfNoRecord = true)
        {
            try
            {
                TraineeRecord tr = TraineeRecords.Where(TraineeRecord => TraineeRecord.Date == d.Date).FirstOrDefault();

                // If there are no records, one will be created with the date specified.
                if (tr == null && CreateIfNoRecord == true)
                {
                    tr = new TraineeRecord(d.Date);
                    TraineeRecords.Add(tr);
                }

                return tr;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return null;
        }
    }
}
